<?php
namespace app\common\controller;
//use think\{Controller,Db,Input};//
use think\Controller;
use think\Lang;
use think\Cookie;
class Base extends Controller{
	public $lang = null;
	public function _initialize(){
		/*语言*/
        if($this->request->has('lang')){
            $lang = $this->request->request('lang');
        }elseif (Cookie::has('think_var')) {
            $lang = Cookie::get('think_var');
        } else {
            $lang = \think\Config::get('default_lang');
        }
        $this->request->langset($lang);
        $module = 'common';
        Lang::load(APP_PATH.$module.DS. 'lang' . DS . $this->request->langset(). EXT);
        $this->lang =  $lang;
        $auth = new \clt\Auth();
	}
	/*改变语言*/
    public function changeLang($lang=null){
        if ($lang == null) {
            if (Cookie::has('think_var')) {
                $lang = Cookie::get('think_var');
            } else {
                $lang = \think\Config::get('default_lang');
            }
        }
        $lang = trim($lang);
        $request = \think\Request::instance();
        $lang = Lang::range($lang);//设定当前语言
        Cookie::set('think_var', $lang);
        \think\View::share('now_lang',$lang);
        return ['code'=>1,'msg'=>''];
    }
}